package com.qf.controller;

import com.qf.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.List;

@Controller
@SessionAttributes(names = {"name","sex"})
public class springMVC {
    @RequestMapping("/param01")
    public String param01(int id,String name,String sex){
        System.out.println(id);
        System.out.println(name);
        System.out.println(sex);
        return "success";
    }

    @RequestMapping("/param02")
    public String param02(User user){
        System.out.println(user.getId());
        System.out.println(user.getName());
        System.out.println(user.getSex());
        return "success";
    }

    @RequestMapping("/param03")
    public String param03(String[] array){
        System.out.println(Arrays.toString(array));

        return "success";
    }

    @RequestMapping("/param04")
    public String param04(@RequestParam("list") List<String> list){
        System.out.println(list);

        return "success";
    }

    @PostMapping("/param05")
    public String param05(int id,String name,String sex){
        System.out.println(id);
        System.out.println(name);
        System.out.println(sex);

        return "success";
    }

    @GetMapping("/param06")
    public String param06(User user, ModelMap map){
        map.put("name","朱玲");
        map.put("sex","男");

        return "success";
    }

    @GetMapping("/param07")
    public String param07(User user, ModelMap map){
        map.put("name","朱玲");
        map.put("sex","男");

        return "success";
    }

    @GetMapping("/param08")
    public ModelAndView param08(ModelAndView mav){
        mav.addObject("name","郭旭东");
        mav.addObject("sex","男");
        mav.setViewName("redirect:/success.jsp");

        return mav;
    }
}
